package edu.maplef.bookwild.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

import edu.maplef.bookwild.config.Constants;

/**
 * 是否已授权验证拦截器
 * @author maple
 *
 */
public class LoginInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 1L;

	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		//判断是否具有授权后的参数
		if (arg0.getInvocationContext().getParameters().containsKey(
				Constants.PARAM_XN_SIG_USER)
				&& arg0.getInvocationContext().getParameters().containsKey(
						Constants.PARAM_XN_SIG_SESSION_KEY)) {
			//如果验证通过则继续程序的正常流程
			//return arg0.invoke();
			//测试期间使用注册代替
			return Constants.NEED_AUTH_KEY;
		} else {
			//如果验证失败，返回授权页面
			return Constants.NEED_AUTH_KEY;
		}
	}
}